package com.csht.service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csht.mapper.CshtTradingSuccessMapper;
import com.csht.model.CshtTradingSuccess;
import com.csht.page.PagerModel;
import com.csht.service.CshtTradingSuccessService;
import com.csht.vo.my.CshtTradingSuccessVo;

/**
 * 交易成功的商品service
 * @author chenhuiyan
 *
 */
@Service
public class CshtTradingSuccessServiceImpl implements CshtTradingSuccessService {
	
	@Autowired
	private CshtTradingSuccessMapper cshtTradingSuccessMapper;

	/**
	 * 根据用户id查找交易成功的数量
	 */
	@Override
	public Integer getTradingSuccessNumberByUserId(Integer userId) throws Exception {
		Integer count = cshtTradingSuccessMapper.getTradingSuccessNumberByUserId(userId);
		return count;
	}

	/**
	 * 根据用户id查找已出售的商品
	 */
	@Override
	public PagerModel<CshtTradingSuccessVo> getTradingSuccessByUserId(Map<String, Integer> res) throws Exception {
		List<CshtTradingSuccessVo> cshtTradingSuccessList = cshtTradingSuccessMapper.getTradingSuccessByUserId(res);
		PagerModel<CshtTradingSuccessVo> pagerModel = new PagerModel<CshtTradingSuccessVo>();
		Integer totalSize = this.getTradingSuccessNumberByUserId(res.get("userId"));
		Integer messagePageSize = res.get("messagePageSize");
		Integer offset = res.get("offset");
		pagerModel.setDates(cshtTradingSuccessList);
		pagerModel.setMessagePageSize(messagePageSize);
		pagerModel.setOffset(offset);
		pagerModel.setTotalSize(totalSize);
		return pagerModel;
	}

	/**
	 * 根据交易成功商品id查找交易成功的商品原id
	 */
	@Override
	public Integer selectTradingSuccessById(Integer tradingSuccessId) throws Exception {
		Integer goodsId = cshtTradingSuccessMapper.selectTradingSuccessById(tradingSuccessId);
		return goodsId;
	}

	/**
	 * 根据id删除交易成功的商品
	 */
	@Override
	public void deleteTradingSuccessById(Integer tradingSuccessId) throws Exception {
		cshtTradingSuccessMapper.deleteTradingSuccessById(tradingSuccessId);
	}

	/**
	 * 插入一条记录
	 */
	@Override
	public void insertTradingSuccessGoods(CshtTradingSuccess cshtTradingSuccess) throws Exception {
		cshtTradingSuccessMapper.insertTradingSuccessGoods(cshtTradingSuccess);
	}

}
